package com.lengyu.vxminiprogram.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lengyu.vxminiprogram.convert.IInstanceMonsterConverter;
import com.lengyu.vxminiprogram.dto.InstanceMonsterDto;
import com.lengyu.vxminiprogram.entity.InstanceMonster;
import com.lengyu.vxminiprogram.entity.InstanceMonsterSkill;
import com.lengyu.vxminiprogram.mapper.InstanceMonsterMapper;
import com.lengyu.vxminiprogram.service.IInstanceMonsterService;
import com.lengyu.vxminiprogram.service.IInstanceMonsterSkillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liuyu
 * @since 2025-03-05
 */
@Service
public class InstanceMonsterServiceImpl extends ServiceImpl<InstanceMonsterMapper, InstanceMonster> implements IInstanceMonsterService {

    @Autowired
    IInstanceMonsterSkillService skillService;

    @Autowired
    IInstanceMonsterConverter monsterConverter;

    @Override
    public List<InstanceMonsterDto> getListByInstanceId(String instanceId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("instance_id",instanceId);
        queryWrapper.orderByAsc("boss_index");
        List<InstanceMonster> monsterList = list(queryWrapper);
        List<InstanceMonsterDto> monsterDtoList = monsterConverter.listEntityToDto(monsterList);
        if(monsterDtoList != null && monsterDtoList.size() > 0){
            monsterDtoList.forEach(i->{
                QueryWrapper queryWrapper1 = new QueryWrapper();
                queryWrapper1.eq("monster_id",i.getId());
                List<InstanceMonsterSkill> skillList = skillService.list(queryWrapper1);
                i.setSkillList(skillList);
            });
            return monsterDtoList;
        }
        else{
            return null;
        }
    }
}
